#include "elevatorsystem.h"

#include<algorithm>

ElevatorSystem::ElevatorSystem()

{
    elevator[0] = new Elevator(0);
    elevator[1] = new Elevator(1);
}

ElevatorSystem::~ElevatorSystem(){
    delete elevator[0];
    delete elevator[1];
}

void ElevatorSystem::distribute(int floor, Direction direction)
{
    if(elevator[0]->getDirection()==IDLE&&elevator[1]->getDirection()==IDLE){
        if(abs(elevator[0]->getCurrentFloor()-floor)<=abs(elevator[1]->getCurrentFloor()-floor)){
            elevator[0]->call(floor);
        }else{
            elevator[1]->call(floor);
        }
        return;
    }
    if(elevator[0]->getDirection()==IDLE){
        elevator[0]->call(floor);
    }else if(elevator[1]->getDirection()==IDLE){
        elevator[1]->call(floor);
    }
}

